package com.maoye.ossp.biz.standard.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hotent.base.api.query.QueryFilter;
import com.hotent.base.api.query.QueryOP;
import com.hotent.base.core.util.string.StringUtil;
import com.maoye.ossp.biz.standard.entry.StandardAssortCondition;
import com.maoye.ossp.biz.standard.entry.StandardCondition;
import com.maoye.ossp.biz.standard.service.StandardAssortService;
import com.maoye.ossp.biz.standard.utils.StrandardUtils;
import com.maoye.ossp.common.entity.Page;
import com.maoye.ossp.common.web.BaseController;
import com.maoye.ossp.sys.org.util.UserUtils;

/**
 * 招商标准
* @ClassName: StandardContraoller
* @Description: 
* @Company: MOI
* @author linzhizhong
* @date 2014年5月25日 上午1:04:41
*
 */
@Controller
@RequestMapping("biz/satndardAssort/")
public class StandardAssortController extends BaseController {
	
	@Resource
	StandardAssortService standardAssortService;
	
	
	
	@RequestMapping(value = "list")
	public String list(StandardCondition standard,Model mode, HttpServletRequest request) {
		QueryFilter queryFilter = getQuerFilter(request, standard);
		String createById =standard.getCreateBy();
		String createBy = null;
		if(StringUtil.isNotEmpty(createById)){
			createBy = createById.split("\\|")[0];
		}
		queryFilter.addFilter("areaId", standard.getAreaId(), QueryOP.EQUAL);
		queryFilter.addFilter("floorId", standard.getFloorId(), QueryOP.EQUAL);
		queryFilter.addFilter("storeId", standard.getStoreId(), QueryOP.EQUAL);
		queryFilter.addFilter("startDate", standard.getStartDate(), QueryOP.EQUAL);
		queryFilter.addFilter("endDate", standard.getEndDate(), QueryOP.EQUAL);
		if(StringUtil.isNotEmpty(standard.getOpeateStatus())){
			queryFilter.addFilter("opeateStatus", standard.getOpeateStatus(), QueryOP.EQUAL);
		}
		queryFilter.addFilter("createBy", createBy, QueryOP.EQUAL);
		Page<StandardAssortCondition> page=standardAssortService.find(queryFilter);
		mode.addAttribute("page", page);
		mode.addAttribute("standard", standard);
		return resultPage("/biz/contract/satndardAssort/list", mode, request);
	}


	
	@RequestMapping(value="add")
	public String add(StandardCondition standard,HttpServletRequest request,HttpServletResponse response, Model mode){
		//associatedContract.setRecieveStatus("0");
		standard.setCreateBy(UserUtils.getUser().getId().toString());
		standard.setOpeateStatus(StrandardUtils.STRANDARD_STATE_ADD);
		mode.addAttribute("standard", standard);
		return resultPage("/biz/contract/satndardAssort/add", mode, request) ;
	}
	
	
	

	@RequestMapping(value = "save")
	public String save(StandardAssortCondition standard, Model model,RedirectAttributes redirectAttributes, HttpServletRequest request,HttpServletResponse response,String remove_Contact,String delContactId) {
		String navId = request.getParameter("navId");
		standardAssortService.SaveStandardCondition(standard,delContactId);
		addMessage(redirectAttributes, "保存成功:");
		return "redirect:/biz/satndardAssort/list?navId="+navId;
		
	}
	
	
	@RequestMapping(value ="{id}/view")
	public String view(@PathVariable String id,Model model,
			RedirectAttributes redirectAttributes, HttpServletRequest request,
			HttpServletResponse response) {
		//合同基本信息
		StandardAssortCondition standard = standardAssortService.get(Long.parseLong(id));
		model.addAttribute("standard", standard);
		
		model.addAttribute("assItemsList", standard.getListAssitems());
		return resultPage("/biz/contract/satndardAssort/view",model,request);
	}
	
	
	@RequestMapping(value ="{id}/supplierView")
	public String supplierView(@PathVariable String id,Model model,
			RedirectAttributes redirectAttributes, HttpServletRequest request,
			HttpServletResponse response) {
		//合同基本信息
		StandardAssortCondition standard = standardAssortService.get(Long.parseLong(id));
		model.addAttribute("standard", standard);
		
		model.addAttribute("assItemsList", standard.getListAssitems());
		return resultPage("/biz/contract/satndardAssort/supplierView",model,request);
	}
	
	
	
	@RequestMapping(value ="{id}/purView")
	public String purView(@PathVariable String id,Model model,
			RedirectAttributes redirectAttributes, HttpServletRequest request,
			HttpServletResponse response) {
		//合同基本信息
		StandardAssortCondition standard = standardAssortService.get(Long.parseLong(id));
		model.addAttribute("standard", standard);
		
		model.addAttribute("assItemsList", standard.getListAssitems());
		return resultPage("/biz/contract/satndardAssort/purView",model,request);
	}
	
	
	@RequestMapping(value = "{ids}/removeBatch")
	public String removeBatch(@PathVariable String ids, HttpServletRequest request,Model model,RedirectAttributes redirectAttributes) {
		String navId = request.getParameter("navId");
		standardAssortService.removeBatch(ids);
		redirectAttributes.addFlashAttribute(navId);
		return "redirect:/biz/satndardAssort/list?navId="+navId;
	}
	
	

/**********
 * 合同修
 * 
 * @param id
 * @param model
 * @param redirectAttributes
 * @return
 * @author eric
 * @data 2014年3月7日
 */
@RequestMapping(value = "{id}/edit")
public String edit(@PathVariable String id, Model model,RedirectAttributes redirectAttributes,HttpServletRequest request) {

	StandardAssortCondition standard = standardAssortService.get(Long.parseLong(id));
	model.addAttribute("standard", standard);
	
	model.addAttribute("assItemsList", standard.getListAssitems());
	return resultPage("/biz/contract/satndardAssort/add",model,request);

}
}
